home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group95c.txt / 000083_icon-group-sender _Sun Nov 12 20:23:40 1995.msg < prev    next >
Internet Message Format  |  1996-01-03  |  1KB

  1. Received: by cheltenham.cs.arizona.edu; Wed, 22 Nov 1995 10:43:36 MST
  2. To: icon-group@cs.arizona.edu
  3. Date: 12 Nov 1995 20:23:40 GMT
  4. From: john@nmt.edu (John Shipman)
  5. Message-Id: <485l4c$erl@newshost.nmt.edu>
  6. Organization: New Mexico Tech Computer Center
  7. Sender: icon-group-request@cs.arizona.edu
  8. Subject: Comparing sets for equality
  9. Errors-To: icon-group-errors@cs.arizona.edu
  10.  
  11. I need an Icon function to test two sets to see if they're identical.
  12.  
  13. Is there an operator that does this, that I have somehow missed?
  14.  
  15. If not, here's how I implemented it.  I reasoned that if the two
  16. sets are the same size, and their set difference is zero, then they
  17. must be identical.  Questions:
  18.  
  19. 1. Is my reasoning correct?
  20.  
  21. 2. Is this more or less the fastest way to do this?
  22.  
  23. 3. Is there anything wrong with my implementation (below)?
  24.  
  25. ----------------------------------------------------------------
  26.  
  27. #-[ If x and y are sets with identical elements ->
  28. #     returns y
  29. # | else if x and y are sets with non-identical elements ->
  30. #     fails
  31. #-]
  32.  
  33. procedure Set_Equal ( x, y )
  34.   if  ( ( * x ) = ( * y ) ) &           # If element counts are the same...
  35.       ( ( * ( x -- y ) ) = 0 )  then    # ...and set difference is empty
  36.     return y
  37.   else
  38.     fail;
  39. end
  40. John Shipman, js@cs.nmt.edu, http://www.nmt.edu/~john
  41. Zoological Data Processing, 507 Fitch NW, Socorro, NM 87801 USA
  42.